package com.yishe.controller.wx.sign;

import com.yishe.biz.wx.WxSignBiz;
import com.yishe.config.ObjectRestResponse;
import com.yishe.entites.vo.SignVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;
import java.util.Map;

/**
 * @author : chusifeng
 * @version :
 * @date :Create in 2021/4/14 12:33
 * @description: 微信工具
 * @package com.yishe.controller.wx
 * @className WxController
 */
@RestController
@Slf4j
@RequestMapping("/wx/sign")
public class WxSignController {
    @Resource
    private WxSignBiz wxSignBiz;

    /**
     * create by: chusifeng
     * Create in 2021/4/17 13:45
     * Description:根据用户账号和日期获取本月的签到历史数据
     * <p>Example</p>
     */
    @PostMapping(value = "getSignHistory")
    public ObjectRestResponse getSignHistory(@RequestBody Map<String, String> params) {
        ObjectRestResponse restResponse = new ObjectRestResponse();
        if (params.isEmpty()){
            restResponse.setErrorMsg("参数有误");
            return restResponse;
        }
        try {
           SignVo signVo =  wxSignBiz.getSignHistory(params);
           restResponse.setData(signVo);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return restResponse;
    }
    /**
     * create by: chusifeng
     * Create in 2021/4/17 13:45
     * Description:根据用户账号和日期获取本月的签到历史数据
     * <p>Example</p>
     */
    @PostMapping(value = "createSign")
    public ObjectRestResponse createSign(@RequestBody SignVo signVoInput) {
        ObjectRestResponse restResponse = new ObjectRestResponse();
        if (null == signVoInput){
            restResponse.setErrorMsg("参数有误");
            return restResponse;
        }
        try {
            SignVo signVo =  wxSignBiz.createSign(signVoInput);
            restResponse.setData(signVo);
        } catch (Exception e) {
            e.printStackTrace();
            restResponse.setErrorMsg("签到出错："+e.getMessage());
        }
        return restResponse;
    }
}
